package cn.icatw.gulimall.search.controller;

import cn.icatw.gulimall.search.service.MallSearchService;
import cn.icatw.gulimall.search.vo.SearchParam;
import cn.icatw.gulimall.search.vo.SearchResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;


/**
 * 搜索控制器
 *
 * @author icatw
 * @date 2022/3/14
 * @email 762188827@qq.com
 * @apiNote
 */
@Controller
@Slf4j
public class SearchController {
    @Autowired
    MallSearchService mallSearchService;


    /**
     * 列表页面
     *
     * @param param   参数
     * @param model   模型
     * @param request 请求
     * @return {@link String}
     */
    @GetMapping("/list.html")
    public String listPage(SearchParam param, Model model, HttpServletRequest request) {
        param.set_queryString(request.getQueryString());
        SearchResult result = mallSearchService.search(param);
        model.addAttribute("result", result);
        //log.info(result.getCatalogs().toString());
        //System.out.println(result.getCatalogs());
        return "list";
    }
}
